package kam.fire;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;

public class OptionsController extends Activity {

	DatabaseHelper db = DatabaseHelper.getHelper(this);
	Options options = new Options();
	boolean autoSave;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.options);
		updateUI();

	}

	@Override
	public void onResume() {
		super.onResume();
		updateUI();
	}

	private void updateUI() {
		options = db.getOptions();
		if (options.getAutoSaveFiles()) {
			CheckBox autoSaveCB = (CheckBox) findViewById(R.id.AutoSaveBox);
			autoSaveCB.setChecked(options.getAutoSaveFiles());
		}
	}

	public void cancelButton(View v) {
		finish();
	}

	public void saveButton(View v) {
		setOptionValues();
		saveOptions();
		finish();
	}

	private void setOptionValues() {
		// TODO Auto-generated method stub
		CheckBox autoSaveCB = (CheckBox) findViewById(R.id.AutoSaveBox);
			options.setAutoSaveFiles(autoSaveCB.isChecked());
	}

	private void saveOptions() {
		db.addOptions(options);
	}
}